﻿// WARNING!! AUTO GENERATED CODE!!
// MODIFY THE .tt/.t4 FILE FOR PERMANENT CHANGE

using System;
using System.Collections.Generic;
using DXBase;
using DXBase.Structs;

namespace DXBase.Assimp
{
	// unfortunately generics and pointers don't mix
	// these methods provide a workaround

	#region PointerInt32 : Pointer<int>

	/// <summary>
	/// A list item with an underlying native pointer as backing storage.
	/// Beware this item is unsafe, no bounds checking on many methods
	/// </summary>
	public class PointerInt32 : Pointer<int>
	{
		public PointerInt32() {}
		public PointerInt32(INativePointer p) : base(p) {}

		// convenient method
		unsafe new public int* GetPointer() { return (int*)base.GetPointer(); }

		// === required
		public unsafe override int this[int index]
		{
			get { return GetPointer()[index]; }
			set { GetPointer()[index] = value; }
		}

		// === performance improvement
		protected unsafe override void CopyRangeAt(int index, ICollection<int> items)
		{
			var p = GetPointer();
			p += index;
			foreach (var value in items)
				*p++ = value;
		}

		protected unsafe override void CopyToImpl(int[] array, int arrayIndex, int N)
		{
			var p = GetPointer();
			p += arrayIndex;
			for (int i = 0; i < N; i++)
				array[i] = *p++;
		}

		public unsafe override int IndexOf(int item)
		{
			var p = GetPointer();
			for (int i = 0, N = Count; i < N; i++)
				if (Equals(*p++, item))
					return i;
			return -1;
		}
	}

	#endregion

	#region PointerInt16 : Pointer<short>

	/// <summary>
	/// A list item with an underlying native pointer as backing storage.
	/// Beware this item is unsafe, no bounds checking on many methods
	/// </summary>
	public class PointerInt16 : Pointer<short>
	{
		public PointerInt16() {}
		public PointerInt16(INativePointer p) : base(p) {}

		// convenient method
		unsafe new public short* GetPointer() { return (short*)base.GetPointer(); }

		// === required
		public unsafe override short this[int index]
		{
			get { return GetPointer()[index]; }
			set { GetPointer()[index] = value; }
		}

		// === performance improvement
		protected unsafe override void CopyRangeAt(int index, ICollection<short> items)
		{
			var p = GetPointer();
			p += index;
			foreach (var value in items)
				*p++ = value;
		}

		protected unsafe override void CopyToImpl(short[] array, int arrayIndex, int N)
		{
			var p = GetPointer();
			p += arrayIndex;
			for (int i = 0; i < N; i++)
				array[i] = *p++;
		}

		public unsafe override int IndexOf(short item)
		{
			var p = GetPointer();
			for (int i = 0, N = Count; i < N; i++)
				if (Equals(*p++, item))
					return i;
			return -1;
		}
	}

	#endregion
}

